<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="88px">
      <el-form-item label="日期：" prop="type">
        <el-date-picker v-model="dateTime" :editable="false" type="date" size="small" value-format="yyyy-MM-dd" @change="onChangeDate"
          :picker-options="pickerOptions" placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="园所性质：" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择园所性质" clearable size="small">
          <el-option v-for="dict in schoolTypeOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="地区类型：" prop="type">
        <el-select v-model="queryParams.nature" placeholder="请选择地区类型" clearable size="small">
          <el-option v-for="dict in schoolNatureOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="园所名称：" prop="name">
        <el-input v-model="queryParams.name" @input="handleInput" placeholder="请输入园所名称" clearable size="small" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="checkSchoolList">
      <el-table-column type="index" align="center" label="序号" width="80"></el-table-column>
      <el-table-column align="center" label="园所名称" prop="schoolName"></el-table-column>
      <el-table-column align="center" label="园所性质" prop="schoolType" :formatter="schoolTypeFormat"></el-table-column>
      <el-table-column align="center" label="地区类型" prop="nature" :formatter="schoolNatureFormat"></el-table-column>
      <el-table-column align="center" label="正常率%" prop="normalPro"></el-table-column>
      <el-table-column align="center" label="异常人数" prop="abnormal"></el-table-column>
      <el-table-column align="center" label="传染病">0</el-table-column>

      <!-- <el-table-column align="center" label="传染病人数" prop="bj"></el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)"
            v-if="scope.row.schoolName !== '全区'">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getcheckSchool" />
    <!-- <div class="charts"  >
        <div class="title">入园率{{ 95 }}%</div>
            <div  ref="chartpDom" class="chart_dom"></div>
    </div> -->
    <!-- 园所内各个班级晨检情况 -->
    <el-dialog title="班级晨检情况" :visible.sync="open" width="70%" append-to-body>
      <el-form :model="classParams" ref="queryForm" :inline="true" label-width="88px">

        <el-form-item label="班级：" prop="class">
          <el-select v-model="classParams.class" placeholder="请选择班级" clearable size="small">
            <el-option v-for="item in classOptions" :key="item.id" :label="item.title" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="classQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="classReset">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="checkClassList">
        <el-table-column type="index" align="center" label="序号" :index="customeIndex" width="80"></el-table-column>
        <el-table-column align="center" label="班级" prop="className"></el-table-column>
        <el-table-column align="center" label="正常率%" prop="normalPro"></el-table-column>
        <el-table-column align="center" label="异常人数" prop="abnormal"></el-table-column>
        <!-- <el-table-column align="center" label="传染病人数" prop="bj"></el-table-column> -->
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-view" @click="handleClass(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="classtotal > 0" :total="classtotal" :page.sync="classParams.pageNum"
        :limit.sync="classParams.pageSize" @pagination="getcheckClass" />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="classOk">确 定</el-button>
        <el-button @click="classCancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 单个幼儿入园情况 -->
    <el-dialog title="幼儿晨检情况" :visible.sync="childOpen" width="75%" append-to-body>
      <el-form :model="childParams" ref="queryForm" :inline="true" label-width="88px">
        <el-form-item label="幼儿名称：" prop="name">
          <el-input v-model="childParams.name" placeholder="请输入幼儿名称" clearable size="small" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="childQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="childReset">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="checkChildList">
        <el-table-column type="index" align="center" label="序号" :index="customeIndex" width="80"></el-table-column>
        <el-table-column align="center" label="检查时间" prop="checkTime" width="180"></el-table-column>
        <el-table-column align="center" label="姓名" prop="name"></el-table-column>
        <el-table-column align="center" label="性别" prop="studentSex" :formatter="sexFormat"></el-table-column>
        <el-table-column align="center" label="年龄" prop="studentAge"></el-table-column>
        <el-table-column align="center" label="身高/cm" prop="height"></el-table-column>
        <el-table-column align="center" label="体重/kg" prop="weight"></el-table-column>
        <el-table-column align="center" label="体温/°C" prop="temperature"></el-table-column>
        <el-table-column align="center" label="牙齿" prop="teethStatus">
          <template slot-scope="scope">
            <div v-if="scope.row.teethStatus == '1'">异常</div>
            <div v-if="scope.row.teethStatus == '0'">正常</div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="眼睛" prop="eyeStatus">
          <template slot-scope="scope">
            <div v-if="scope.row.eyeStatus == '1'">异常</div>
            <div v-if="scope.row.eyeStatus == '0'">正常</div>
            <div v-if="scope.row.eyeStatus == '2'">未检查</div>
          </template>
        </el-table-column>
        <!-- <el-table-column  align="center" label="咽喉"  prop="shijia"></el-table-column> -->
        <el-table-column align="center" label="手部" prop="handStatus">
          <template slot-scope="scope">
            <div v-if="scope.row.handStatus == '1'">异常</div>
            <div v-if="scope.row.handStatus == '0'">正常</div>
            <div v-if="scope.row.handStatus == '2'">未检查</div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="口腔" prop="oralStatus">
          <template slot-scope="scope">
            <div v-if="scope.row.oralStatus == '1'">异常</div>
            <div v-if="scope.row.oralStatus == '0'">正常</div>
            <div v-if="scope.row.oralStatus == '2'">未检查</div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="指甲" prop="nailsStatus">
          <template slot-scope="scope">
            <div v-if="scope.row.nailsStatus == '1'">过长</div>
            <div v-if="scope.row.nailsStatus == '0'">正常</div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="外伤" prop="traumaStatus">
          <template slot-scope="scope">
            <div v-if="scope.row.traumaStatus == '1'">异常</div>
            <div v-if="scope.row.traumaStatus == '0'">正常</div>
            <div v-if="scope.row.traumaStatus == '2'">未检查</div>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="childtotal > 0" :total="childtotal" :page.sync="childParams.pageNum"
        :limit.sync="childParams.pageSize" @pagination="getcheckKid" />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="childOk">确 定</el-button>
        <el-button @click="childCancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { checkSchool, checkClass, checkKid } from "@/api/qu/qyyecjzx";
import { clazzList } from "@/api/qu/qyyerygk";

import moment from "moment";
export default {
  name: "qyyecjzx",
  data() {
    return {
      loading: false,
      dateTime: new Date(),
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
      schoolCode: '',
      // 查询参数
      queryParams: {
        name: '',
        nature: '',
        type: '',
        pageNum: 1,
        pageSize: 10,
      },
      schoolNatureOptions: [],
      schoolTypeOptions: [],
      // 性别字典
      sexOptions: [],
      classOptions: [],
      checkSchoolList: [
        { name: '幼儿园', yiruyuan: '2', shijia: '2', bj: '3', ryl: '95%' }
      ],
      total: 0,
      checkClassList: [],
      classtotal: 0,
      checkChildList: [],
      childtotal: 0,
      open: false,
      classParams: {
        class: '',
        grade: '',
        pageNum: 1,
        pageSize: 10,
      },
      childParams: {
        name: '',
        pageNum: 1,
        pageSize: 10,
      },
      classId: '',
      childOpen: false,
    }
  },
  created() {
    this.getDicts("park_type").then(response => {
      this.schoolTypeOptions = response.data;
    });
    this.getDicts("sys_user_sex").then(response => {
      this.sexOptions = response.data;
    });
    this.getDicts("school_nature").then(response => {
      this.schoolNatureOptions = response.data;
    });
    this.getcheckSchool()
  },
  methods: {
    // 学校层面
    async getcheckSchool() {
      this.loading = true;
      try {
        const obj = {
          schoolName: this.queryParams.name,
          schoolType: this.queryParams.type,
          nature: this.queryParams.nature,
          checkDate: moment(this.dateTime).format("YYYY-MM-DD"),
          pageNum: this.queryParams.pageNum,
          pageSize: this.queryParams.pageSize,
        }
        const data = await checkSchool(obj)
        this.checkSchoolList = data.rows;
        this.total = data.total;
        this.loading = false;
      } catch (error) {
        console.log(error);
      }
    },
    // 班级层面
    async getcheckClass(val) {
      this.loading = true;
      try {
        const obj = {
          schoolCode: this.schoolCode,
          classId: this.classParams.class,
          checkDate: moment(this.dateTime).format("YYYY-MM-DD"),
          pageNum: this.classParams.pageNum,
          pageSize: this.classParams.pageSize,
        }
        const data = await checkClass(obj)
        this.checkClassList = data.rows;
        this.classtotal = data.total;
        this.loading = false;
      } catch (error) {
        console.log(error);
      }
    },
    // 幼儿层面
    async getcheckKid(row) {
      this.loading = true;
      try {
        const obj = {
          schoolCode: this.schoolCode,
          name: this.childParams.name,
          classId: this.classId,
          checkDate: moment(this.dateTime).format("YYYY-MM-DD"),
          pageNum: this.childParams.pageNum,
          pageSize: this.childParams.pageSize,
        }
        const data = await checkKid(obj)
        this.checkChildList = data.rows;
        this.childtotal = data.total;
        this.loading = false;
      } catch (error) {
        console.log(error);
      }
    },
    //clazzList 获取班级列表
    async getClazzList() {
      try {
        const obj = {
          schoolCode: this.schoolCode,
        }
        const data = await clazzList(obj)
        this.classOptions = data.rows
      } catch (error) {
        console.log(error);
      }
    },
    // 序号
    customeIndex(index) {
      return index + 1 + (this.queryParams.pageNum - 1) * this.queryParams.pageSize
    },
    // 园所性质字典翻译
    schoolTypeFormat(row, column) {
      return this.selectDictLabel(this.schoolTypeOptions, row.schoolType);
    },
    //地区类型字典翻译
    schoolNatureFormat(row, column) {
      return this.selectDictLabel(this.schoolNatureOptions, row.nature);
    },
    // 性别字典翻译
    sexFormat(row, column) {
      return this.selectDictLabel(this.sexOptions, row.studentSex);
    },
    //打开园所内各个班级弹框
    handleView(row) {
      this.open = true;
      this.schoolCode = row.schoolCode
      this.getClazzList();
      this.getcheckClass();
    },
    classQuery() {
      this.getcheckClass();
    },
    classReset() {
      this.classParams = {
        class: '',
        pageNum: 1,
        pageSize: 10,
      },
        this.classQuery()
    },
    classOk() {
      this.open = false;
      this.classParams = {
        grade: '',
        class: '',
        pageNum: 1,
        pageSize: 10,
      }
    },
    classCancel() {
      this.open = false;
      this.classParams = {
        grade: '',
        class: '',
        pageNum: 1,
        pageSize: 10,
      }
    },
    //打开园所内各个班级的幼儿弹框
    handleClass(row) {
      this.classId = row.classId;
      this.childOpen = true;
      this.getcheckKid()

    },
    //搜索单个幼儿情况
    childQuery() {
      this.getcheckKid()
    },
    //重置单个幼儿情况
    childReset() {
      this.childParams.name = '';
      this.childQuery()
    },
    childOk() {
      this.childOpen = false;
      this.childParams = {
        name: '',
        pageNum: 1,
        pageSize: 10,
      }
    },
    childCancel() {
      this.childOpen = false;
      this.childParams = {
        name: '',
        pageNum: 1,
        pageSize: 10,
      }

    },
    handleInput(val) {
      let regtszf = /[`~!@#$%^&*()_\-+=<>?:"{}|,./;'\\[\]·~！@#￥%……&*（）——\-+={}|《》？：“”【】、；‘'，。、]/g // 特殊字符正则
      let regkg = /[ ]/g// 空格正则
      this.queryParams.name = val.replace(regtszf, '').replace(regkg, '')
    },
    onChangeDate() {

    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;
      this.getcheckSchool();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = {
        type: '',
        nature: '',
        name: ''
      }
      this.dateTime = new Date()
      this.handleQuery();
    },
    chartsFun() {
      const option = {
        // backgroud:'#333',
        title: {
          text: '园所出勤情况统计',
          //  subtext: '纯属虚构',
          left: 'left'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        legend: {},
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            axisLabel: {//x轴文字的配置
              show: true,
              interval: 0,//使x轴文字显示全
            },
            data: ['已入园', '事假', '病假',]
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        color: ['#2f89cf', '#27d08a'],
        series: [
          {
            // name: '出勤情况',
            type: 'bar',
            stack: 'Ad',
            barWidth: '30%',
            emphasis: {
              focus: 'series'
            },
            label: {
              show: true,
              position: 'inside',
              fontSize: 15
            },
            data: [2, 2, 3,],
          },
        ]
      }
      // 使用刚指定的配置项和数据显示图表
      this.charts.setOption(option, true);
      window.addEventListener("resize", this.monitorResize);
    },
    //监听窗口缩放事件
    monitorResize() {
      this.charts.resize();
    },
  }
};
</script>
<style lang="scss" scoped>
.charts {
  // margin-top: 10px;
  width: 75%;
  height: 500px;

  .title {
    position: relative;
    top: 30px;
    left: 45%;
    font-weight: 700;
    font-size: 18px;
    color: #2a77cf;
  }

  // border: 1px red solid;
  .chart_dom {
    width: 100%;
    height: 100%;
  }
}
</style>
